﻿using System;
using System.Data;
using System.Data.SqlClient;
using System.Collections.Generic;
using System.Text;
using Portal.Environment;
using Portal.Language;
using Portal.Interface;

namespace Portal.CMS
{
    public class FocusNews : WebPart
    {
        public override string WebPartId
        {
            get
            {
                return "FocusNews";
            }
        }

        public override bool IsMainWebPart
        {
            get
            {
                return true;
            }
        }

        public override bool RunStandalone
        {
            get
            {
                return true;
            }
        }
        public override string Title
        {
            get
            {
                return ResourceBLL.GetText(WebPartId, "Title", "Tin nổi bật trang chủ");
            }
        }

        public override string Description
        {
            get
            {
                return ResourceBLL.GetText(WebPartId, "Description", "");
            }
        }


        public override WebPartInt[] SubWebParts
        {
            get
            {
                WebPartInt[] SubWebParts = new WebPartInt[]{
                
                };
                return SubWebParts;
            }
        }


        public override string RenderWebPart(LoadParamCls loadParamCls)
        {
            try
            {
                AjaxPro.Utility.RegisterTypeForAjax(typeof(FocusNews));
                //string gfItemId = (string)Environments.Request("gfItemId");
                //string XmlData = Environments.GetXmlWebPartConfigItem(gfItemId);
                //if (XmlData.Trim().Length == 0) throw new Exception(ResourceBLL.GetText(WebPartId, "NotConfig", "Chưa cấu hình hiển thị!"));
                //DataSet ds = new DataSet();
                //ds.ReadXml(new System.IO.StringReader(XmlData));
                //string GroupNewsItemId = (string)ds.Tables[0].Rows[0]["GroupNewsItemId"];

                //GroupNewsItemCls GroupNewsItemCls = new GroupNewsBLL().CreateModelItem(Environments.ActiveLanguage, GroupNewsItemId);
                //if (GroupNewsItemCls == null) return "Chưa xác định nhóm tin cần nhập trong cấu hình thiết lập menu";
                //string GroupNewsId = GroupNewsItemCls.GroupNewsId;
                //GroupNewsCls GroupNewsCls = new GroupNewsBLL().CreateModel(GroupNewsId);
                string RetHtml =
                    WebPartUtilities.AttachJavascript("Portal.CMS", "News.js") +
                    "<div class=cssHeading>" + Title + "</div>" +
                    "<div class=cssNewsMain>" +
                    //"   <input type=hidden value=\"" + GroupNewsId + "\" id=txtGroupNewsId>" +
                    //"   <input type=hidden value=\"" + GroupNewsItemId + "\" id=txtGroupNewsItemId>" +
                    "   <div id=divNewsContent>" + GetHtml(1, 0) + "</div>" +
                    "</div>";
                return RetHtml;
            }
            catch (Exception ex)
            {
                return "ERROR: " + ex.Message.ToString();
            }
        }

        [AjaxPro.AjaxMethod]
        public string GetHtml(
            int WorkFlowStatusIndex,
            int PageIndex)
        {
            try
            {
                Environment.Environments.CheckSessionTimeOut(true);

                string RetHtml = "";
                string belongSite = "vie";
                DataTable dtNews = new NewsBLL().ReadingNews_Hot(belongSite, WorkFlowStatusIndex);
                int ItemPerPage = 20;
                int MaxPage = dtNews.Rows.Count / ItemPerPage;
                if (dtNews.Rows.Count % ItemPerPage != 0) MaxPage++;
                int StartIndex = PageIndex * ItemPerPage;
                int EndIndex = StartIndex + ItemPerPage;
                if (EndIndex > dtNews.Rows.Count) EndIndex = dtNews.Rows.Count;

                string SelectPageText = ResourceBLL.GetText(WebPartId, "PageText", "Trang") + ": <select id=divSelectPage>";
                for (int iIndex = 0; iIndex < MaxPage; iIndex++)
                {
                    if (PageIndex == iIndex)
                    {
                        SelectPageText += "<option selected>" + (iIndex + 1) + "</option>";
                    }
                    else
                    {
                        SelectPageText += "<option>" + (iIndex + 1) + "</option>";
                    }
                }
                SelectPageText += "</select>";
                if (MaxPage == 0) SelectPageText = "";

                string SelectWorkFlowStatusText =
                  GetText("StatusLabel", "Trạng thái") + ":<select id=drpSelectWorkflowStatus>" +
                  "   <option selected value=\"0\">" + ResourceBLL.GetText(WebPartId, "NotPublishingComboxItem", "Chưa phát hành") + "</option>" +
                  "   <option value=\"1\">" + ResourceBLL.GetText(WebPartId, "PublishingComboxItem", "Đã phát hành") + "</option>" +
                  "</select>";
                if (WorkFlowStatusIndex == 1)
                {
                    SelectWorkFlowStatusText =
                        GetText("StatusLabel", "Trạng thái") + ":<select id=drpSelectWorkflowStatus>" +
                        "   <option value=\"0\">" + ResourceBLL.GetText(WebPartId, "NotPublishingComboxItem", "Chưa phát hành") + "</option>" +
                        "   <option selected value=\"1\">" + ResourceBLL.GetText(WebPartId, "PublishingComboxItem", "Đã phát hành") + "</option>" +
                        "</select>";
                }
                RetHtml +=
                    //"<div class=cssNewsFunction>" + SelectPageText + SelectWorkFlowStatusText + "<input type=button onclick=\"javascript:RunFilterStdAlone();\" value=\"" + ResourceBLL.GetText(WebPartId, "ReadingText", "Đọc") + "\"><input type=button value=\"" + ResourceBLL.GetText(WebPartId, "AddText", "Thêm mới") + "\" onclick=javascript:ClientStdAddNews('" + GroupNewsId + "','" + SelectedGroupNewsItemId + "');></div>" +
                    "<div id=divProcessing></div>";

                if (dtNews.Rows.Count == 0)
                {
                    RetHtml += "<div class=\"cssNoData\">" + ResourceBLL.GetText(WebPartId, "NoData", "Chưa có dữ liệu nào trong chuyên mục này!") + "</div>";
                }
                else
                {
                    RetHtml +=
                    "<table class=cssNewsContent>" +
                           "  <tr>" +
                           "      <th class=cssCol0>STT</th>" +
                           "      <th class=cssCol1>" + ResourceBLL.GetText(WebPartId, "SubjectText", "Tiêu đề") + "</th>" +
                        //"      <th class=cssCol3></th>" +
                           "      <th class=cssCol4></th>" +
                           "      <th class=cssCol5></th>" +
                           "      <th class=cssCol6>Xử lý</th>" +
                           " </tr>";
                    for (int iIndex = StartIndex; iIndex < EndIndex; iIndex++)
                    {
                        string NewsId = (string)dtNews.Rows[iIndex]["NewsId"];
                        string SubjectText = "";
                        try
                        {
                            SubjectText = (string)dtNews.Rows[iIndex][Environments.ActiveLanguage + "Subject"];
                        }
                        catch { }
                        int IsPublishing = 0;
                        try
                        {
                            IsPublishing = (int)dtNews.Rows[iIndex]["IsPublishing"];
                        }
                        catch { }
                        DateTime EntryDate = (DateTime)dtNews.Rows[iIndex]["EntryDate"];
                        string tWorkFlowStatus = "";
                        try
                        {
                            tWorkFlowStatus = (string)dtNews.Rows[iIndex]["WorkFlowStatus"];
                        }
                        catch { }

                        string PublishingUrl = "<a href=\"javascript:PublishingStdAloneNewsInFocus('" + NewsId + "');\">" + ResourceBLL.GetText(WebPartId, "Publishing", "(Xuất bản)") + "</a>";
                        if (IsPublishing == 1)
                        {
                            PublishingUrl = "<a href=\"javascript:UnPublishingStdAloneNewsInFocus('" + NewsId + "');\">" + ResourceBLL.GetText(WebPartId, "RemoveFromRemoteServer1", "(Bỏ xuất bản)") + "</a>";
                        }


                        string ImageUrl = "<a href=\"javascript:ClientUploadImageUrlInFocus('" + NewsId + "');\">" + ResourceBLL.GetText(WebPartId, "UploadImages1", "(Cập nhật ảnh)") + "</a>";

                        int ShowOnTop = 0;
                        try
                        {
                            ShowOnTop = (int)dtNews.Rows[iIndex]["ShowOnTop"];
                        }
                        catch { }
                        string ShowOnTopUrl = "<a href=\"javascript:ClientSetShowOnTopInFoCus('" + NewsId + "');\">" + ResourceBLL.GetText(WebPartId, "isFocus", "(Là tin nổi bật)") + "</a>";
                        if (ShowOnTop == 1)
                        {
                            ShowOnTopUrl = "<a href=\"javascript:ClientDisShowOnTopInFoCus('" + NewsId + "');\">" + ResourceBLL.GetText(WebPartId, "noFocus", "(Bỏ tin nổi bật)") + "</a>";
                        }
                        if (IsPublishing == 0) ShowOnTopUrl = "(n/a)";

                        string tbelongSite = (string)dtNews.Rows[iIndex]["belongSite"];
                        string ShortId = (string)dtNews.Rows[iIndex]["ShortId"];
                        string NewsUrl = Environments.GetNewsUrl(belongSite, ShortId, SubjectText, "_runtime");
                        NewsUrl = "<a target=_blank href=\"" + NewsUrl + "\">" + ResourceBLL.GetText(WebPartId, "PreView", "Xem trước") + "</a>";

                        RetHtml +=
                               "  <tr onMouseOver=\"this.className='highlight'\" onMouseOut=\"this.className='normal'\">" +
                               "      <td valign=top>" + (iIndex + 1) + "</td>" +
                               "      <td valign=top class=cssTdSubjectText>" + SubjectText + "<br><span class=cssLinkNews>" + NewsUrl + "</span></td>" +
                            //"      <td valign=top nowrap><a href=\"javascript:ShowUpdateStdAloneNewsForm('" + GroupNewsId + "','" + SelectedGroupNewsItemId + "','" + NewsId + "');\">" + ResourceBLL.GetText(WebPartId, "UpdateText", "Cập nhật") + "</a></td>" +
                               "      <td valign=top>" + ImageUrl + "</td>" +
                               "      <td valign=top>" + ShowOnTopUrl + "</td>" +
                               "      <td valign=top>" + PublishingUrl + "</td>" +
                               " </tr>";
                    }
                    RetHtml += "</table>";
                }
                return RetHtml;
            }
            catch (Exception ex)
            {
                return ex.Message.ToString();
            }
        }



        [AjaxPro.AjaxMethod]
        public string ServerSideGetOpenUrl(string bs)
        {
            return Screen.BuildUrl(WebPartId, new ParamCls[]{
                new ParamCls("bs",bs)
            });
        }

        [AjaxPro.AjaxMethod]
        public string GetProcessingText()
        {
            try
            {
                Environments.CheckSessionTimeOut(true);
                string Url = Environment.Environments.GetActiveThemeUrl() + "/Global/Loading.gif";
                return "<img src=\"" + Url + "\"><a class=cssProcessing>" + ResourceBLL.GetText(WebPartId, "ProcessingText", "Đang đọc dữ liệu...") + "</a>";
            }
            catch (Exception ex)
            {
                return "ERROR: " + ex.Message.ToString();
            }
        }

        public override IWebPartConfig WebConfig
        {
            get
            {
                return new InputNewsConfig();
            }
        }


        [AjaxPro.AjaxMethod]
        public string GetAddNewUrl(string GroupNewsId, string GroupNewsItemId)
        {
            try
            {
                Environments.CheckSessionTimeOut(true);

                PermissionTypeCls PermissionTypeCls = Environments.FindPermissionType(
                             new GroupNews().PermissionTypes, "GroupNewsItems");

                GroupNewsItemCls
                    GroupNewsItemCls = new GroupNewsBLL().CreateModelItem(Environments.ActiveLanguage, GroupNewsItemId);
                Environment.Permission.CheckPermission(Environment.Environments.CurrentLoginUser.LoginName, PermissionTypeCls.PermissionTypeCode, "AddNewsForGroup", GroupNewsItemId, GroupNewsItemCls.Owner, true);
                return Screen.BuildDialogUrl(new ParamCls[]{
                        new ParamCls("WebPartId",new AddNews().WebPartId),
                        new ParamCls("GroupNewsId",GroupNewsId),
                        new ParamCls("GroupNewsItemId",GroupNewsItemId)
                    });
            }
            catch (Exception ex)
            {
                return "ERROR: " + ex.Message.ToString();
            }
        }

        [AjaxPro.AjaxMethod]
        public string GetConfirmMsg()
        {
            return ResourceBLL.GetText(WebPartId, "ConfirmDeleteMsg", "Bạn đã chắc chắn xóa chưa?");
        }

        [AjaxPro.AjaxMethod]
        public string GetConfirmPublishingNewsMsg()
        {
            return ResourceBLL.GetText(WebPartId, "GetConfirmPublishingNewsMsg", "Bạn đã chắc chắn xuất bản lên web (public) chưa?");
        }

        [AjaxPro.AjaxMethod]
        public string GetConfirmUnPublishingNewsMsg()
        {
            return ResourceBLL.GetText(WebPartId, "GetConfirmUnPublishingNewsMsg", "Bạn đã chắc chắn ngừng xuất bản lên web (public) chưa?");
        }

        [AjaxPro.AjaxMethod]
        public string GetDeleteOkMsg()
        {
            return ResourceBLL.GetText(WebPartId, "DeleteOk", "Xóa thành công");
        }

        [AjaxPro.AjaxMethod]
        public string CheckAllowDelete(string NewsId)
        {
            try
            {
                Environment.Environments.CheckSessionTimeOut(true);

                PermissionTypeCls PermissionTypeCls = Environments.FindPermissionType(
                             new GroupNews().PermissionTypes, "GroupNewsItems");
                NewsCls NewsCls = new NewsBLL().CreateModel(Environments.ActiveLanguage, NewsId);
                if (NewsCls == null) throw new Exception(GetText("HasDeleted", "Bản tin đã được xóa!"));
                Environment.Permission.CheckPermission(Environment.Environments.CurrentLoginUser.LoginName, PermissionTypeCls.PermissionTypeCode, "DeleteNewsItem", NewsCls.GroupNewsItemId, NewsCls.Owner, true);

                return "";
            }
            catch (Exception ex)
            {
                return "ERROR: " + ex.Message.ToString();
            }
        }

        [AjaxPro.AjaxMethod]
        public string ServerSideDeleteNews(string NewsId)
        {
            try
            {
                Environment.Environments.CheckSessionTimeOut(true);

                PermissionTypeCls PermissionTypeCls = Environments.FindPermissionType(
                             new GroupNews().PermissionTypes, "GroupNewsItems");
                NewsCls NewsCls = new NewsBLL().CreateModel(Environments.ActiveLanguage, NewsId);
                if (NewsCls == null) throw new Exception(GetText("HasDeleted", "Bản tin đã được xóa!"));
                GroupNewsItemCls GroupNewsItemCls = new GroupNewsBLL().CreateModelItem(Environments.ActiveLanguage, NewsCls.GroupNewsItemId);
                Environment.Permission.CheckPermission(
                    Environment.Environments.CurrentLoginUser.LoginName,
                    PermissionTypeCls.PermissionTypeCode,
                    "DeleteNewsItem", GroupNewsItemCls.GroupNewsItemId, GroupNewsItemCls.Owner, true);


                SqlTransaction sqlTransaction = Environment.Environments.CreateTransaction();
                try
                {
                    new NewsBLL().DeleteNews(sqlTransaction, NewsId);
                    sqlTransaction.Commit();
                }
                catch (Exception ex)
                {
                    sqlTransaction.Rollback();
                    throw (ex);
                }
                return "";
            }
            catch (Exception ex)
            {
                return "ERROR: " + ex.Message.ToString();
            }
        }

        [AjaxPro.AjaxMethod]
        public string GetUpdateNewsUrl(string GroupNewsId, string NewsId)
        {
            try
            {
                Environments.CheckSessionTimeOut(true);

                //PermissionTypeCls PermissionTypeCls = FindPermissionType("News");
                //NewsCls NewsCls = new NewsBLL().CreateModel(Environments.ActiveLanguage, NewsId);
                //Environment.Permission.CheckPermission(Environment.Environments.CurrentLoginUser.LoginName, PermissionTypeCls.PermissionTypeCode, "UpdateNews", NewsId, NewsCls.Owner, true);


                PermissionTypeCls PermissionTypeCls = Environments.FindPermissionType(
                    new GroupNews().PermissionTypes, "GroupNewsItems");
                NewsCls NewsCls = new NewsBLL().CreateModel(Environments.ActiveLanguage, NewsId);
                if (NewsCls == null) throw new Exception(GetText("HasDeleted", "Bản tin đã được xóa!"));
                GroupNewsItemCls GroupNewsItemCls = new GroupNewsBLL().CreateModelItem(Environments.ActiveLanguage, NewsCls.GroupNewsItemId);

                if (NewsCls.IsPublishing == 0)
                {

                    Environment.Permission.CheckPermission(
                        Environment.Environments.CurrentLoginUser.LoginName,
                        PermissionTypeCls.PermissionTypeCode,
                        "UpdateNewsItem", GroupNewsItemCls.GroupNewsItemId, GroupNewsItemCls.Owner, true);
                }
                else
                {
                    Environment.Permission.CheckPermission(
                       Environment.Environments.CurrentLoginUser.LoginName,
                       PermissionTypeCls.PermissionTypeCode,
                       "UpdateNewsItemHasPublic", GroupNewsItemCls.GroupNewsItemId, GroupNewsItemCls.Owner, true);
                }

                return Screen.BuildDialogUrl(new ParamCls[]{
                        new ParamCls("WebPartId",new UpdateNews().WebPartId),
                        new ParamCls("GroupNewsId",GroupNewsId),
                        new ParamCls("NewsId",NewsId)
                    });
            }
            catch (Exception ex)
            {
                return "ERROR: " + ex.Message.ToString();
            }
        }



        [AjaxPro.AjaxMethod]
        public string GetUpdateImageUrl(string NewsId)
        {
            try
            {
                Environments.CheckSessionTimeOut(true);

                return Screen.BuildDialogUrl(new ParamCls[]{
                        new ParamCls("WebPartId",new UploadImage().WebPartId),
                        new ParamCls("NewsId",NewsId)
                    });
            }
            catch (Exception ex)
            {
                return "ERROR: " + ex.Message.ToString();
            }
        }



        [AjaxPro.AjaxMethod]
        public string GetMoveNewsUrl(string NewsId)
        {
            try
            {
                Environments.CheckSessionTimeOut(true);

                return Screen.BuildDialogUrl(new ParamCls[]{
                        new ParamCls("WebPartId",new MoveNews().WebPartId),
                        new ParamCls("NewsId",NewsId)
                    });
            }
            catch (Exception ex)
            {
                return "ERROR: " + ex.Message.ToString();
            }
        }

        [AjaxPro.AjaxMethod]
        public string ServerSidePublishingNews(string NewsId)
        {
            try
            {
                Environments.CheckSessionTimeOut(true);
                PermissionTypeCls PermissionTypeCls = Environments.FindPermissionType(
                            new GroupNews().PermissionTypes, "GroupNewsItems");

                NewsCls NewsCls = new NewsBLL().CreateModel(Environments.ActiveLanguage, NewsId);
                Environment.Permission.CheckPermission(Environment.Environments.CurrentLoginUser.LoginName, PermissionTypeCls.PermissionTypeCode, "PublishingNews", NewsCls.GroupNewsItemId, NewsCls.Owner, true);

                new NewsBLL().PublishingPublicWebSite(NewsId);
                return ResourceBLL.GetText(WebPartId, "PublishingOk", "Xuất bản tin lên web thành công!");
            }
            catch (Exception ex)
            {
                return "ERROR: " + ex.Message.ToString();
            }
        }


        [AjaxPro.AjaxMethod]
        public string ServerSideUnPublishingNews(string NewsId)
        {
            try
            {
                Environments.CheckSessionTimeOut(true);
                PermissionTypeCls PermissionTypeCls = Environments.FindPermissionType(
                            new GroupNews().PermissionTypes, "GroupNewsItems");

                NewsCls NewsCls = new NewsBLL().CreateModel(Environments.ActiveLanguage, NewsId);
                Environment.Permission.CheckPermission(Environment.Environments.CurrentLoginUser.LoginName, PermissionTypeCls.PermissionTypeCode, "PublishingNews", NewsCls.GroupNewsItemId, NewsCls.Owner, true);

                new NewsBLL().UnPublishingPublicWebSite(NewsId);
                return ResourceBLL.GetText(WebPartId, "UnPublishingOk", "Ngừng xuất bản tin lên web thành công!");
            }
            catch (Exception ex)
            {
                return "ERROR: " + ex.Message.ToString();
            }
        }


        [AjaxPro.AjaxMethod]
        public string CheckAllowPublishingNews(string NewsId)
        {
            try
            {
                Environments.CheckSessionTimeOut(true);
                PermissionTypeCls PermissionTypeCls = Environments.FindPermissionType(
                            new GroupNews().PermissionTypes, "GroupNewsItems");

                NewsCls NewsCls = new NewsBLL().CreateModel(Environments.ActiveLanguage, NewsId);
                Environment.Permission.CheckPermission(Environment.Environments.CurrentLoginUser.LoginName, PermissionTypeCls.PermissionTypeCode, "PublishingNews", NewsCls.GroupNewsItemId, NewsCls.Owner, true);
                return "";
            }
            catch (Exception ex)
            {
                return "ERROR: " + ex.Message.ToString();
            }
        }



        [AjaxPro.AjaxMethod]
        public string GetShowFormSetPermission(string NewsId)
        {
            try
            {
                Environment.Environments.CheckSessionTimeOut(true);
                PermissionTypeCls PermissionTypeCls = Environments.FindPermissionType(
                            new GroupNews().PermissionTypes, "GroupNewsItems");

                NewsCls NewsCls = new NewsBLL().CreateModel(Environments.ActiveLanguage, NewsId);
                Environment.Permission.CheckPermission(Environment.Environments.CurrentLoginUser.LoginName, PermissionTypeCls.PermissionTypeCode, "PermissionNews", NewsCls.GroupNewsItemId, NewsCls.Owner, true);
                return Environment.Permission.GetPermissionUrl(WebPartId, NewsId, "News");
            }
            catch (Exception ex)
            {
                return "ERROR: " + ex.Message.ToString();
            }
        }



        [AjaxPro.AjaxMethod]
        public string GetLogUrl(string NewsId)
        {
            try
            {
                Environment.Environments.CheckSessionTimeOut(true);
                string LogUrl = Screen.BuildDialogUrl(new NewsHistory().WebPartId, new ParamCls[]{
                        new ParamCls("NewsId",NewsId)
                    });
                return LogUrl;

            }
            catch (Exception ex)
            {
                return "ERROR: " + ex.Message.ToString();
            }
        }


        [AjaxPro.AjaxMethod]
        public string ServerSideSetShowOnTop(string NewsId)
        {
            try
            {
                Environment.Environments.CheckSessionTimeOut(true);
                PermissionTypeCls PermissionTypeCls = Environments.FindPermissionType(
                            new GroupNews().PermissionTypes, "GroupNewsItems");


                NewsCls NewsCls = new NewsBLL().CreateModel(Environments.ActiveLanguage, NewsId);
                Environment.Permission.CheckPermission(Environment.Environments.CurrentLoginUser.LoginName, PermissionTypeCls.PermissionTypeCode, "UpdateNews", NewsCls.GroupNewsItemId, NewsCls.Owner, true);
                new NewsBLL().SetOnTop(null, NewsCls.GroupNewsItemId, NewsId);
                return ResourceBLL.GetText(WebPartId, "SetOnTopOk", "Đặt tin nổi bật thành công!");
            }
            catch (Exception ex)
            {
                return "ERROR: " + ex.Message.ToString();
            }
        }

        [AjaxPro.AjaxMethod]
        public string ServerSideDisShowOnTop(string NewsId)
        {
            try
            {
                Environment.Environments.CheckSessionTimeOut(true);
                PermissionTypeCls PermissionTypeCls = Environments.FindPermissionType(
                            new GroupNews().PermissionTypes, "GroupNewsItems");


                NewsCls NewsCls = new NewsBLL().CreateModel(Environments.ActiveLanguage, NewsId);
                Environment.Permission.CheckPermission(Environment.Environments.CurrentLoginUser.LoginName, PermissionTypeCls.PermissionTypeCode, "UpdateNews", NewsCls.GroupNewsItemId, NewsCls.Owner, true);
                new NewsBLL().DisOnTop(null, NewsCls.GroupNewsItemId, NewsId);
                return ResourceBLL.GetText(WebPartId, "DisOnTopOk", "Bỏ tin nổi bật thành công!");
            }
            catch (Exception ex)
            {
                return "ERROR: " + ex.Message.ToString();
            }
        }

        [AjaxPro.AjaxMethod]
        public string ServerSideSyncToServer(string NewsId)
        {
            try
            {
                Environments.CheckSessionTimeOut(true);
                new NewsBLL().SyncNews(NewsId);
                return ResourceBLL.GetText(WebPartId, "SyncToServer", "Cập nhật thành công!");
            }
            catch (Exception ex)
            {
                return "ERROR: " + ex.Message.ToString();
            }
        }

        [AjaxPro.AjaxMethod]
        public string GetConfirmSyncAllMsg()
        {
            return ResourceBLL.GetText(WebPartId, "ConfirmSyncAllMsg", "Bạn đã chắc chắn update lại dữ liệu tin tức trên máy chủ từ máy local chưa?");
        }



        [AjaxPro.AjaxMethod]
        public string GetSyncProcessing()
        {
            return ResourceBLL.GetText(WebPartId, "SyncProcessing", "Đang cập dữ liệu cho máy chủ public...");
        }

        [AjaxPro.AjaxMethod]
        public string GetProcessingMsg()
        {
            return ResourceBLL.GetText(WebPartId, "ProcessingMsg", "Đang đọc dữ liệu...");
        }

        [AjaxPro.AjaxMethod]
        public string GetUploadDocumentContentUrl(string belongSite, string NewsId)
        {
            try
            {
                Environments.CheckSessionTimeOut(true);
                PermissionTypeCls PermissionTypeCls = Environments.FindPermissionType(
                            new GroupNews().PermissionTypes, "GroupNewsItems");

                NewsCls NewsCls = new NewsBLL().CreateModel(Environments.ActiveLanguage, NewsId);
                Environment.Permission.CheckPermission(Environment.Environments.CurrentLoginUser.LoginName, PermissionTypeCls.PermissionTypeCode, "UpdateNews", NewsCls.GroupNewsItemId, NewsCls.Owner, true);

                return Screen.BuildDialogUrl(new NewsUploadDocument().WebPartId, new ParamCls[]{
                    new ParamCls("belongSite",belongSite),
                    new ParamCls("NewsId",NewsId)
                });
            }
            catch (Exception ex)
            {
                return "ERROR: " + ex.Message.ToString();
            }
        }

        [AjaxPro.AjaxMethod]
        public string ServerSideResetDocumentContent(string belongSite, string NewsId)
        {
            try
            {
                Environments.CheckSessionTimeOut(true);
                new NewsBLL().ResetDocumentContent(null, NewsId);
                return "Thành công loại bỏ nội dung gắn kèm";
            }
            catch (Exception ex)
            {
                return "ERROR: " + ex.Message.ToString();
            }
        }


        [AjaxPro.AjaxMethod]
        public string GetRelationFormUrl(string NewsId)
        {
            try
            {
                Environments.CheckSessionTimeOut(true);

                return Screen.BuildDialogUrl(new ParamCls[]{
                        new ParamCls("WebPartId",new UpdateRelationNews().WebPartId),
                        new ParamCls("NewsId",NewsId)
                    });
            }
            catch (Exception ex)
            {
                return "ERROR: " + ex.Message.ToString();
            }
        }

        [AjaxPro.AjaxMethod]
        public string GetAttachmentFormUrl(string NewsId)
        {
            try
            {
                Environments.CheckSessionTimeOut(true);

                return Screen.BuildDialogUrl(new ParamCls[]{
                        new ParamCls("WebPartId",new UpdateAttachmentsNews().WebPartId),
                        new ParamCls("NewsId",NewsId)
                    });
            }
            catch (Exception ex)
            {
                return "ERROR: " + ex.Message.ToString();
            }
        }
    }
}